package com.dtx.prototype.shushang;

import com.dtx.prototype.gongyoude.framework.Product;

/**
 * UnderlinePen类的实现与MessageBox几乎完全相同,不同的是在ulchar字段中保存的是修饰下划线样式的字符。
 * use方法的作用是将字符串用双引号括起来显式,并在字符串下面加上下划线。例如,当ulchar保存的字符为'~',
 * use方法接收到的字符串为Hello时,显示结果如下。
 *      "Hello"
 *      ~~~~~
 */
public class UnderlinePen implements Product {

    private char ulchar;

    public UnderlinePen(char ulchar) {
        this.ulchar = ulchar;
    }

    @Override
    public void use(String s) {

        int length = s.getBytes().length;

        System.out.println("\"" + s + "\"");

        System.out.print(" ");

        for (int i = 0; i < length; i++) {
            System.out.print(ulchar);
        }

        System.out.println("");
    }

    @Override
    public Product createClone() {

        Product p = null;

        try {
            p = (Product) clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

        return p;
    }
}
